<?php


namespace app\web\model;


use app\lib\model\Price;

class Platform extends Base
{
    public function getCreateTimeAttr($v)
    {
        return date('Y-m-d H:i',$v);
    }
    public function getBeforeBalanceAttr($v){
        return (float)$v;
    }
    public function getChangeBalanceAttr($v){
        return (float)$v;
    }
    public function getAfterBalanceAttr($v){
        return (float)$v;
    }
    public static $platform_type = ['用户充值','用户消费','加项补差','用户退款','用户提现','技师提现','商家提现'];
    public static function change(array $data)
    {
        $last = self::where('id','>',0)->order('id','desc')->find();
        $before_balance = $last ? $last->after_balance : 0;
        $after_balance = Price::pricecalc($before_balance,'+',$data['change_balance']);
        $data['before_balance'] = $before_balance;
        $data['after_balance'] = $after_balance;
        $res = self::create($data);
        if($res->isEmpty()) return false;
        return true;
    }
}